package cn.schoolwow.quickdao.module.database.parent.flow.executor.common;

import cn.schoolwow.quickdao.domain.QuickDAOConfig;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class RecordStatementFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String name = flowContext.checkData("name", String.class);
        String content = flowContext.checkData("content", String.class);
        QuickDAOConfig quickDAOConfig = flowContext.checkInstanceData(QuickDAOConfig.class);

        if(quickDAOConfig.logRecordOption.record&&!"插入SQL日志".equalsIgnoreCase(name)){
            ThreadLocal<StringBuffer> sqlRecordBuilderThreadLocal = quickDAOConfig.logRecordOption.sqlRecordBuilderThreadLocal;
            StringBuffer sqlRecordBuilder = sqlRecordBuilderThreadLocal.get();
            if(null==sqlRecordBuilder){
                sqlRecordBuilderThreadLocal.set(new StringBuffer());
            }
            sqlRecordBuilder = sqlRecordBuilderThreadLocal.get();
            sqlRecordBuilder.append(content);
        }
    }

    @Override
    public String name() {
        return "记录SQL语句";
    }
}
